package com.winderinfo.yikaotianxia.ui.report;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.winderinfo.yikaotianxia.R;
import com.winderinfo.yikaotianxia.core.base.BaselanFragment;
import com.winderinfo.yikaotianxia.core.utils.LogUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class QuestionFragment extends BaselanFragment {
    @BindView(R.id.quet_type)
    TextView quetType;
    @BindView(R.id.quet_sum)
    TextView quetSum;
    @BindView(R.id.quet_num)
    TextView quetNum;
    @BindView(R.id.quet_title)
    TextView quetTitle;
    @BindView(R.id.quet_a)
    TextView quetA;
    @BindView(R.id.quet_b)
    TextView quetB;
    @BindView(R.id.quet_c)
    TextView quetC;
    @BindView(R.id.quet_d)
    TextView quetD;
    @BindView(R.id.quet_ta)
    TextView quetTa;
    @BindView(R.id.quet_tb)
    TextView quetTb;
    @BindView(R.id.quet_tc)
    TextView quetTc;
    @BindView(R.id.quet_td)
    TextView quetTd;
    @BindView(R.id.quet_zhengque)
    TextView quetZhengque;
    @BindView(R.id.quet_cuowu)
    TextView quetCuowu;
    @BindView(R.id.quet_jiexi)
    TextView quetJiexi;
    @BindView(R.id.quet_xuanxiang)
    LinearLayout quetXuanxiang;
    @BindView(R.id.quet_danant)
    TextView quetDanant;
    @BindView(R.id.quet_danan)
    LinearLayout quetDanan;
    Unbinder unbinder;
    private QuestionListBean.YkScoreBean.YkAnswerRecordsBean list;

    @Override
    protected int layoutResID() {
        return R.layout.item_analyticalanswer;
    }

    @Override
    protected void initView(View view) {
        int sum = getArguments().getInt("sum");
        int num = getArguments().getInt("num");
        list = (QuestionListBean.YkScoreBean.YkAnswerRecordsBean) getArguments().getSerializable("list");
        quetNum.setText(sum + "");
        quetSum.setText((1 + num) + "");
        quetTitle.setText(list.getYkTitle().getTitleTitl() + "");
        if (list.getYkTitle().getTitleTypeId() == 1) {
            quetType.setText("单选题");
        }
        if (list.getYkTitle().getTitleTypeId() == 2) {
            quetType.setText("多选题");
        }
        if (list.getYkTitle().getTitleTypeId() == 3) {
            quetType.setText("判断题");
            quetDanan.setVisibility(View.GONE);
            quetDanant.setVisibility(View.GONE);
            quetXuanxiang.setVisibility(View.GONE);
            quetA.setVisibility(View.GONE);
            quetB.setVisibility(View.GONE);
            quetC.setVisibility(View.GONE);
            quetD.setVisibility(View.GONE);
        }
        if (list.getYkTitle().getTitleTypeId() == 4) {
            quetType.setText("简答题");
            quetDanan.setVisibility(View.GONE);
            quetDanant.setVisibility(View.GONE);
            quetXuanxiang.setVisibility(View.GONE);
            quetA.setVisibility(View.GONE);
            quetB.setVisibility(View.GONE);
            quetC.setVisibility(View.GONE);
            quetD.setVisibility(View.GONE);
        }
        if (list.getYkTitle().getTitleTypeId() == 5) {
            quetType.setText("论述题");
            quetDanan.setVisibility(View.GONE);
            quetDanant.setVisibility(View.GONE);
            quetXuanxiang.setVisibility(View.GONE);
            quetA.setVisibility(View.GONE);
            quetB.setVisibility(View.GONE);
            quetC.setVisibility(View.GONE);
            quetD.setVisibility(View.GONE);
        }
        //选项
        if (list.getYkTitle().getYkAnswers().get(0).getAnswerContent() != null) {
            quetTa.setText(list.getYkTitle().getYkAnswers().get(0).getAnswerContent());
        }
        if (list.getYkTitle().getYkAnswers().get(1).getAnswerContent() != null) {
            quetTb.setText(list.getYkTitle().getYkAnswers().get(1).getAnswerContent());
        }
        if (list.getYkTitle().getYkAnswers().get(2).getAnswerContent() != null) {
            quetTc.setText(list.getYkTitle().getYkAnswers().get(2).getAnswerContent());
        }
        if (list.getYkTitle().getYkAnswers().get(3).getAnswerContent() != null) {
            quetTd.setText(list.getYkTitle().getYkAnswers().get(3).getAnswerContent());
        }
        //正确答案
        quetZhengque.setText(list.getYkTitle().getZhengque());

        //我的答案
        if (list.getRemarks() != null) {
            quetCuowu.setText(list.getRemarks());
        } else {
            quetCuowu.setText("未选");
        }


        //单选
        if (list.getYkTitle().getTitleTypeId() == 1) {
            //正确答案
            if (list.getYkTitle().getZhengque() != null) {
                if (list.getYkTitle().getZhengque().equals(list.getRemarks())) {
                    String remarks = list.getRemarks();
                    if (remarks.equals(quetA.getText())) {
                        quetA.setBackgroundResource(R.mipmap.dui);
                        quetA.setTextColor(this.getResources().getColor(R.color.colorWhite));
                    }
                    if (remarks.equals(quetB.getText())) {
                        quetB.setBackgroundResource(R.mipmap.dui);
                        quetB.setTextColor(this.getResources().getColor(R.color.colorWhite));
                    }
                    if (remarks.equals(quetC.getText())) {
                        quetC.setBackgroundResource(R.mipmap.dui);
                        quetC.setTextColor(this.getResources().getColor(R.color.colorWhite));
                    }
                    if (remarks.equals(quetD.getText())) {
                        quetD.setBackgroundResource(R.mipmap.dui);
                        quetD.setTextColor(this.getResources().getColor(R.color.colorWhite));
                    }
                } else {//错误答案
                    String remarks = list.getRemarks();
                    if (remarks != null) {
                        if (remarks.equals(quetA.getText())) {
                            quetA.setBackgroundResource(R.mipmap.cuo);
                            quetA.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (remarks.equals(quetB.getText())) {
                            quetB.setBackgroundResource(R.mipmap.cuo);
                            quetB.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (remarks.equals(quetC.getText())) {
                            quetC.setBackgroundResource(R.mipmap.cuo);
                            quetC.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (remarks.equals(quetD.getText())) {
                            quetD.setBackgroundResource(R.mipmap.cuo);
                            quetD.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                    }
                }
            }

            //解析
            List<QuestionListBean.YkScoreBean.YkAnswerRecordsBean.YkTitleBean.YkAnswersBean> ykAnswers = list.getYkTitle().getYkAnswers();
            for (int i = 0; i < ykAnswers.size(); i++) {
                if (ykAnswers.get(i).getAnswerType().equals(list.getYkTitle().getZhengque())) {
                    quetJiexi.setText(ykAnswers.get(i).getTitleInterpretation());
                    return;
                }
            }
        }

        //多选
        if (list.getYkTitle().getTitleTypeId() == 2) {
            List<QuestionListBean.YkScoreBean.YkAnswerRecordsBean.YkTitleBean.YkAnswersBean> ykAnswers = list.getYkTitle().getYkAnswers();
            if (list.getYkTitle().getZhengque() != null) {
                String remarks = list.getRemarks();
                String[] split = remarks.split(",");
                //对
                if (list.getYkTitle().getZhengque().equals(list.getRemarks())) {
                    for (int i = 0; i < split.length; i++) {
                        if (quetA.getText().equals(split[i])) {
                            quetA.setBackgroundResource(R.mipmap.dui);
                            quetA.setTextColor(this.getResources().getColor(R.color.colorWhite));

                        }
                        if (quetB.getText().equals(split[i])) {
                            quetB.setBackgroundResource(R.mipmap.dui);
                            quetB.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (quetC.getText().equals(split[i])) {
                            quetC.setBackgroundResource(R.mipmap.dui);
                            quetC.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (quetD.getText().equals(split[i])) {
                            quetD.setBackgroundResource(R.mipmap.dui);
                            quetD.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                    }
                } else {//错的
                    LogUtil.i("split1", "456");
                    for (int i = 0; i < split.length; i++) {
                        if (quetA.getText().equals(split[i])) {
                            quetA.setBackgroundResource(R.mipmap.cuo);
                            quetA.setTextColor(this.getResources().getColor(R.color.colorWhite));

                        }
                        if (quetB.getText().equals(split[i])) {
                            quetB.setBackgroundResource(R.mipmap.cuo);
                            quetB.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (quetC.getText().equals(split[i])) {
                            quetC.setBackgroundResource(R.mipmap.cuo);
                            quetC.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                        if (quetD.getText().equals(split[i])) {
                            quetD.setBackgroundResource(R.mipmap.cuo);
                            quetD.setTextColor(this.getResources().getColor(R.color.colorWhite));
                        }
                    }

                }
            }
            //答案
            //解析
            String zhengque = list.getYkTitle().getZhengque();
            String[] split1 = zhengque.split(",");
            if (ykAnswers.size() > 0) {
                for (int i = 0; i < ykAnswers.size(); i++) {
                    if (split1.length > 0) {
                        if (ykAnswers.get(i).getAnswerType().equals(split1[0])) {
                            quetJiexi.setText(ykAnswers.get(i).getTitleInterpretation());
                            return;
                        }
                    }
                }
            }
        }

    }

    @Override
    protected void loadData() {


    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
